<template>
  <div class="goods">
 
    <el-breadcrumb separator-class="el-icon-arrow-right">
  <el-breadcrumb-item :to="{ path: '/about' }">首页</el-breadcrumb-item>
  <el-breadcrumb-item>商品管理</el-breadcrumb-item>
  <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>

<el-card>
  <el-row :gutter="22">
    <el-col :span="7">
       <el-input placeholder="请输入内容" clearable  v-model="form.query" @clear="getlist" >
       <el-button slot="append" icon="el-icon-search" @click="getlist"></el-button>
       </el-input>
     </el-col>
      <el-col :span="1">
         <el-button type="primary" @click="add">添加</el-button>
       
     </el-col>
 </el-row>

 
  <el-table
    :data="list"
    border
    style="width: 100%">
     <el-table-column
      type="index"
      label="#"
     >
    
    </el-table-column>
    <el-table-column
      prop="goods_name"
      label="商品名称"
     >
    </el-table-column>
    <el-table-column
      prop="goods_price"
      label="商品价格"
     >
    </el-table-column>
    <el-table-column
      prop="goods_weight"
      label="商品重量">
    </el-table-column>
     <el-table-column
      prop="add_time"
      label="创建时间">
       <template slot-scope="scope">
        {{scope.row.add_time | dateFormat}}
     </template>
    </el-table-column>
    <!--  -->
    
      <el-table-column
      prop="address"
      label="操作">
     <template slot-scope="scope">
       <el-button type="primary" icon="el-icon-edit" circle></el-button>
       <el-button type="danger" icon="el-icon-delete" circle @click="deler(scope.row)">
      </el-button>
       </template>
    </el-table-column>
   
  </el-table>
 

<!-- 分页器 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="form.pagenum"
      :page-sizes="[1, 3, 5, 8,10,20,30]"
      :page-size="form.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      background
      >
    </el-pagination>

</el-card>

  </div>
</template>
<script>

  
export default {

  data() {
    return{
      form:{
     
       query :'' ,
       pagenum:1  ,
       pagesize:6
      },
      
      
      total:0,
      list:[],
      dig:false,
    }
  },
  components:{
   
  },
  created(){
   this.getlist()
  },
  methods:{
  async getlist(){
   const {data:res}=await this.$http.get('goods',{params: this.form})
   console.log(res.data.goods);
   this.list=res.data.goods
   this.total=res.data.total
   },
   add(){
     this.$router.push('/goods/add')
    //  this.dig=true
   },
  async digs(){
    const {data:res}=await this.$http.post('goods',this.forms)
    console.log(res);
   },
  //  分页器
  handleSizeChange(val){
    this.form.pagesize=val
    this.getlist()
   
  },
  handleCurrentChange(val){
    this.form.pagenum=val
    this.getlist()
  },
 async deler(row){
   const {data:res}=await this.$http.delete(`goods/${row.goods_id}`)
   this.$message.success('删除成功')
   this.getlist()
  

  }
  }
}
</script>


<style lang="less" scoped>
.el-card{
  margin-top: 20px;
}
/deep/.el-card__body{
line-height: 20px; 
text-align: left;
}
.el-table{
  margin-top: 30px;
}
</style>
